using System;
using System.Configuration;
using System.Data;
using digit.Core;

namespace SMS.ServiceManager
{
    public class SportTeamManager
    {
        #region CONSTRUCTORS
        static SportTeamManager()
        {
            _data = new SportTeamData(Util.GetConnectionString("SMSSERVICE"));
            _error = "";
        }
        #endregion

        #region ATTRIBUTES
        private static SportTeamData _data;
        private static string _error;
        #endregion

        #region PROPERTIES
        public static string ErrorMessage
        {
            get
            {
                return _error;
            }
        }

        #endregion

        #region METHODS
        public static bool Insert(string teamName, string teamCode, string teamCodeOpen, string msg1, string msg2, string msg3, string msg4, string msg5, byte type, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[10];
                values[0] = Util.ReplaceNullTo(teamName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(teamCode, DBNull.Value); ;
                values[2] = Util.ReplaceNullTo(teamCodeOpen, DBNull.Value);
                values[3] = Util.ReplaceNullTo(msg1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(msg2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(msg3, DBNull.Value);
                values[6] = Util.ReplaceNullTo(msg4, DBNull.Value);
                values[7] = Util.ReplaceNullTo(msg5, DBNull.Value);
                values[8] = Util.ReplaceNullTo(type, DBNull.Value);
                values[9] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Insert(SportTeamInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[10];
                values[0] = Util.ReplaceNullTo(info.TeamName, DBNull.Value);
                values[1] = Util.ReplaceNullTo(info.TeamCode, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.TeamCodeOpen, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.Msg1, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Msg2, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Msg3, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Msg4, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Msg5, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Type, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Insert(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(int teamID, string teamName, string teamCode, string teamCodeOpen, string msg1, string msg2, string msg3, string msg4, string msg5, byte type, byte status)
        {
            _error = "";
            try
            {
                object[] values = new object[11];
                values[0] = teamID;
                values[1] = Util.ReplaceNullTo(teamName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(teamCode, DBNull.Value); ;
                values[3] = Util.ReplaceNullTo(teamCodeOpen, DBNull.Value);
                values[4] = Util.ReplaceNullTo(msg1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(msg2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(msg3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(msg4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(msg5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(type, DBNull.Value);
                values[10] = Util.ReplaceNullTo(status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Update(SportTeamInfo info)
        {
            _error = "";
            try
            {
                object[] values = new object[11];
                values[0] = info.TeamID;
                values[1] = Util.ReplaceNullTo(info.TeamName, DBNull.Value);
                values[2] = Util.ReplaceNullTo(info.TeamCode, DBNull.Value);
                values[3] = Util.ReplaceNullTo(info.TeamCodeOpen, DBNull.Value);
                values[4] = Util.ReplaceNullTo(info.Msg1, DBNull.Value);
                values[5] = Util.ReplaceNullTo(info.Msg2, DBNull.Value);
                values[6] = Util.ReplaceNullTo(info.Msg3, DBNull.Value);
                values[7] = Util.ReplaceNullTo(info.Msg4, DBNull.Value);
                values[8] = Util.ReplaceNullTo(info.Msg5, DBNull.Value);
                values[9] = Util.ReplaceNullTo(info.Type, DBNull.Value);
                values[10] = Util.ReplaceNullTo(info.Status, DBNull.Value);

                return _data.Update(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(int teamID)
        {
            _error = "";
            try
            {
                object[] values = { teamID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static bool Delete(SportTeamInfo info)
        {
            _error = "";
            try
            {
                object[] values = { info.TeamID };
                return _data.Delete(values);
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return false;
            }
        }

        public static SportTeamInfo Select(int teamID)
        {
            _error = "";
            try
            {
                object[] values = { teamID };
                DataTable dTable = _data.Select(values);
                if (dTable.Rows.Count < 1) return null;


                SportTeamInfo info = new SportTeamInfo(dTable.Rows[0]);
                return info;
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        public static DataTable SelectAll()
        {
            _error = "";
            try
            {
                return _data.SelectAll();
            }
            catch (Exception ex)
            {
                _error = ex.Message;
                return null;
            }
        }

        #endregion

    }
}